package LeetCode;

import java.util.HashMap;
import java.util.Map;

public class LC_532_KdiffPairsinanArray {

    public static void main(String[] args) {

    }

    class Solution {
        public int findPairs(int[] nums, int k) {
            if (nums == null || nums.length == 0 || k < 0) return 0;
            Map<Integer, Integer> map = new HashMap<>();
            int i = 0;
            for (int num : nums) map.put(num, i++);
            int res = 0;
            for (i = 0; i < nums.length; i++)
                if (map.containsKey(nums[i] + k) && map.get(nums[i] + k) != i) {
                    map.remove(nums[i] + k);
                    res++;
                }
            return res;
        }

    }
}